<template>
	<view class='wrapp'>
		<view class='head'>
			<view class='headItem'>
				<view class='headTitle'>
				  <text>设备</text>
				  <text>{{minerNo}}</text>
				</view>
				<view class='headInfo'>
					<text>mac地址</text>
					<text>{{hardware.Mac}}</text>
				</view>
				<view class='headInfo'>
					<text>CPU</text>
					<text>E5_2670</text>
				</view>
				<view class='headInfo'>
					<text>内存</text>
					<text>{{mem_free}}</text>
				</view>
				<view class='headInfo'>
					<text>硬盘</text>
					<text>{{free}}</text>
				</view>
			</view>
		</view>

		<view v-if="checkPropertyData.length != 0">
			<view class='node' v-for="(item,index) in checkPropertyData" :key="index">
				<view class='nodeItem'>
					<view class='nodeInfo'>
						<text>ID</text>
						<text class='nodeInfoWord'>{{item.nodeId}}</text>
					</view>
					<view class='nodeInfo'>
						<text>分配</text>
						<text class='nodeInfoWord'>{{item.nodeInfo.allocs}}</text>
					</view>
					<view class='nodeInfo'>
						<text>在线时间</text>
						<text class='nodeInfoWord'>{{item.nodeInfo.uptime}}</text>
					</view>
					<view class='nodeInfo'>
						<text>已分享空间</text>
						<text class='nodeInfoWord'>{{item.nodeInfo.shared}}</text>
					</view>
				</view>
			</view>
		</view>

		<view class='noNodeView' v-else>暂无信息</view>
	</view>
</template>

<script>
	import api from '../../common/apis.js'
	import message from '../../common/message.js'
	import util from '../../common/util.js'
	export default {
		data() {
			return {
				minerId: '',
				minerNo: '',
				headData: '',
				daemon: '',
				core: '',
				protocol: '',
				cpu: '',
				Mem: '',
				Disk: '',
				system: '',
				hardware: '',
				mem_total: '',
				mem_free: '',
				all: '',
				free: '',
				checkPropertyData: [],
				nodeId: ''
			};
		},
		onLoad: function(options) {
			this.minerId = options.minerId
			this.getMinerDetail(this.minerId);
		},
		methods: {
			getMinerDetail(minerid) {
				let token = uni.getStorageSync("authorization");
				uni.showLoading({
					title: "加载中"
				});
				uni.request({
					url: api.minerDetail + minerid,
					method: "GET",
					header: {
						Authorization: "Bearer " + token
					},
					success:res=> {
						uni.hideLoading();
						if (res.statusCode == 200) {
							let data = res.data;
							this.minerNo = data.minerNo
							this.chuli(data);
							let checkProperty = data.nodeList;
							for (let i = 0; i < checkProperty.length; i++) {
								checkProperty[i].nodeInfo = JSON.parse(checkProperty[i].nodeInfo);
								checkProperty[i].nodeId = util.hideWord(checkProperty[i].nodeId);
							}
							this.checkPropertyData = checkProperty
						} else {
							util.errHandler(res);
						}
					}
				});
			},

			chuli(element) {
				let jsonSytem = {};
				let jsonHardware = {};
				if (element.systemInfo) {
					let temp = util.replaceAll(element.systemInfo, "\\\\", "");
					if (JSON.parse(temp)) {
						jsonSytem = JSON.parse(temp);
					}
				}

				if (element.hardwareInfo) {
					let temp = util.replaceAll(element.hardwareInfo, "\\\\", "");
					if (JSON.parse(temp)) {
						jsonHardware = JSON.parse(temp);
					}
				}
				let a = jsonSytem.storj_version;
				let arry = a.split(",");
				let daemon_1 = arry[0];
				let core_1 = arry[1];
				let protocol_1 = arry[2];
				let cpu_1 = jsonHardware.Cpu.processors[0].model_name;

				this.system = jsonSytem;
				this.hardware = jsonHardware;
				this.daemon = jsonHardware;
				this.core = core_1;
				this.protocol = protocol_1;
				this.cpu = cpu_1;
				this.mem_total = (jsonHardware.Mem.mem_total / 1024.0 / 1024.0).toFixed(2);
				this.mem_free = (jsonHardware.Mem.mem_free / 1024.0 / 1024.0).toFixed(2);
				this.all = (jsonHardware.Disk.all / 1024.0 / 1024.0).toFixed(2);
				this.free = (jsonHardware.Disk.free / 1024.0 / 1024.0).toFixed(2);
			}
		}
	}
</script>

<style>
	.wrapp {
		padding-top: 30px;
		background: rgba(245, 245, 245, 1);
		padding-bottom: 60upx;
	}

	.headItem {
		width: 100%;
		margin-top: 5px;
	}

	.headTitle {
		display: flex;
		justify-content: space-between;
		height: 25px;
		font-size: 16px;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		line-height: 25px;
		border-bottom: 1px solid rgba(153, 153, 153, 0.3);
		padding: 0 20px;
	}

	.head {
		height: 135px;
		background: rgba(255, 255, 255, 1);
		border-radius: 8px;
		width: 80%;
		margin: 0 auto;
		padding: 10px 20px;
	}

	.headInfo {
		display: flex;
		justify-content: space-between;
		height: 25px;
		font-size: 12px;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		line-height: 25px;
		border-bottom: 1px solid rgba(153, 153, 153, 0.3);
		padding: 0 20px;
	}

	.node {
		height: 106px;
		background: rgba(255, 255, 255, 1);
		border-radius: 8px;
		width: 80%;
		margin: 0 auto;
		margin-top: 20px;
		padding: 10px 20px;
	}

	.nodeInfo {
		display: flex;
		justify-content: space-between;
		height: 25px;
		font-size: 12px;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		line-height: 25px;
		border-bottom: 1px solid rgba(153, 153, 153, 0.3);
		padding: 0 20px;
	}

	.nodeInfoWord {
		color: rgba(51, 117, 253, 1);
	}

	.noNodeView {
		width: 80%;
		margin: 15px auto;
		text-align: center;
	}

	.more {
		margin-top: 17px;
		font-size: 10px;
		font-family: PingFangSC-Medium;
		font-weight: 500;
		color: rgba(153, 153, 153, 1);
		text-align: center;
		letter-spacing: 0.72px;
	}
</style>
